{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/wenan/index')}">文案管理</a></li>
            <li class="layui-this">添加文案</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/wenan/save')}" method="post">
                    <div class="layui-form-item" id="leixing1">
                        <label class="layui-form-label">所属分类</label>
                        <div class="layui-input-block">
                            <select name="wid" lay-verify="required" lay-filter="one">
                                <option value="">请选择分类</option>
                                {foreach name="category_level_list" item="vo"}
                                <option value="{$vo.id}">{eq name="vo.level" value="1"}{$vo.name}{/eq} </option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" value="" required  lay-verify="required" placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">缩略图</label>
                        <div class="layui-input-block">
                            <input type="text" name="thumb" value="" class="layui-input layui-input-inline" id="thumb">
                            <input type="file" name="file" class="layui-upload-file">
                        </div>
                    </div> 
                    <div class="layui-form-item">
                        <label class="layui-form-label">文案压缩包(zip格式)</label>
                        <div class="layui-input-block">
                            <input type="text" name="compress" value="" class="layui-input layui-input-inline" id="compress">
                            <input type="file" name="zip" class="layui-upload-file">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <textarea name="remark" placeholder="（选填）请输入备注" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" value="0" required  lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="*">保存</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script src="__JS__/kindeditor/kindeditor.config.js"></script>
<script src="__JS__/kindeditor/kindeditor-all-min.js"></script>
{/block}
{block name="script"}
<script>
    layui.use('form', function(){
    var form = layui.form();
        form.on('select(one)', function(data){
            // console.log(data.value); //得到被选中的值
            $('#leixing2').remove();
            $.get('/admin/wenan/getChildMenu',{id:data.value},function(res){
                if(res.length > 0){
                    var options = '';
                    for(var i = 0;i < res.length;i++){
                        options += '<option value="'+res[i].id+'">'+res[i].name+'</option>';
                    }

                    $('#leixing1').after('<div class="layui-form-item" id="leixing2"><label class="layui-form-label">所属栏目</label><div class="layui-input-block"><select name="pid" lay-verify="required" lay-filter="two"><option value="">请选择栏目</option>'+options+'</select></div></div>');
                    form.render('select');
                }
            });
        });

        form.on('select(two)', function(data){
            // console.log(data.value); //得到被选中的值
            $('#leixing3').remove();
            $.get('/admin/wenan/getChildMenu',{id:data.value},function(res){
                if(res.length > 0){
                    var options = '';
                    for(var i = 0;i < res.length;i++){
                        options += '<option value="'+res[i].id+'">'+res[i].name+'</option>';
                    }

                    $('#leixing2').after('<div class="layui-form-item" id="leixing3"><label class="layui-form-label">所属子类</label><div class="layui-input-block"><select name="pid" lay-verify="required" lay-filter="thr"><option value="">请选择子类</option>'+options+'</select></div></div>');
                    form.render('select');
                }
            });
        });
    //各种基于事件的操作，下面会有进一步介绍
    });
</script>
{/block}